import pygame
from sys import exit

pygame.init()

screen = pygame.display.set_mode([640,480])

def create_scales(height):
    reds = pygame.surface.Surface((640,height))
    blues = pygame.surface.Surface((640, height))
    greens = pygame.surface.Surface((640, height))

    for x in range(640):
        c = int((x/639)*255)

        red = (c,0,0)
        blue = (0,c,0)
        green = (0,0,c)
        line_rect = pygame.Rect(x,0,1,height)
        pygame.draw.rect(reds, red, line_rect)
        pygame.draw.rect(blues, blue, line_rect)
        pygame.draw.rect(greens, green, line_rect)

    return reds,greens,blues

red,green,blue = create_scales(80)

color = [0,0,0]
color_x = [0,0,0]
mousedown = False

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.display.quit()
            exit()
        elif event.type == pygame.MOUSEBUTTONDOWN:
            mousedown = True
        elif event.type == pygame.MOUSEBUTTONUP:
            mousedown = False
    screen.blit(red,(0,0))
    pygame.draw.rect(screen,[255,255,255],[color_x[0],0,10,80],0)
    screen.blit(green, (0, 80))
    pygame.draw.rect(screen, [255, 255, 255], [color_x[1], 80, 10, 80], 0)
    screen.blit(blue, (0, 160))
    pygame.draw.rect(screen, [255, 255, 255], [color_x[2], 2*80, 10, 80], 0)
    x,y = pygame.mouse.get_pos()
    if mousedown:
        if y<3*80:
            color_index = y//80
            color_x[color_index] = x
            color[color_index] = int((x/639)*255)
    pygame.display.set_caption("Pygame 颜色测试 - " + str(tuple(color)))
    pygame.draw.rect(screen,tuple(color),(0,240,640,480))
    pygame.display.update()
pygame.quit()


